//
//  MXFindTwoTableViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/14.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXFindTwoTableViewCell.h"
#import "MXFindBlockTypeTwoTableViewCell.h"
#import "MXNewViewItemDetailVC.h"
#import "MXFindWebViewVC.h"
@interface MXFindTwoTableViewCell ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, assign) NSInteger itemNm;

@end
@implementation MXFindTwoTableViewCell

- (void)dealloc
{
    [_naviTwo release];
    [_model release];
    [_tableView release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatTableView];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
// 根据数组中个数来确定高度
    self.tableView.frame = CGRectMake(0, 0, self.frame.size.width, self.itemNm * HEIGHTPRO * 100);
    
}
- (void)creatTableView
{
    CGFloat WID = self.frame.size.width;
    self.tableView = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, WID, self.itemNm * HEIGHTPRO * 100) style:(UITableViewStylePlain)] autorelease];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.contentView addSubview:self.tableView];
}

/************************************** TableView Delegate 协议实现部分 **********************/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning 根据数据计算
    return self.itemNm;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 需要自定义cell
    MXFindBlockTypeTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    if (!cell) {
        cell = [[MXFindBlockTypeTwoTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"resue"];
    }
    
    [cell getInfo:self.model rowNum:indexPath.row];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return HEIGHTPRO * 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MXFindWebViewVC *ItemVC = [[[MXFindWebViewVC alloc] init] autorelease];
    
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dic in self.model.product) {
        [arr addObject:[dic objectForKey:@"url"]];
    }
    
    ItemVC.requestString = arr[indexPath.row];
    
    ItemVC.TitleString = @"商品详情";

    [self.naviTwo pushViewController:ItemVC animated:YES];
}

-(void)setModel:(MXFindDetailModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    self.itemNm = model.product.count;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
